package www.webols.utils;

import java.util.Iterator;
import java.util.Map;

public class StringUtil {
	public static final String WEIBO_OAUTH_URL="https://api.weibo.com/2/oauth2/authorize?client_id=3723310027&display=mobile&redirect_uri=http://dev.19lou.cn&response_type=code";
	public static final String WEIBO_APP_KEY="3723310027";
	public static final String WEIBO_APP_SECRET="2a5fce0539beddf093f976ed188d3d58";
	public static final String WEIBO_REDIRECT_URL="http://dev.19lou.cn";
	
	public static boolean isCallBackUrl(String url){
		if(url.indexOf("dev.19lou.cn")>0){
			return true;
		}
		return false;
	}
	public static String getWeiboCode(String callbackUrl){
		int index=callbackUrl.indexOf("code=");
		if(index>0){
			return callbackUrl.substring(index+5);
		}
		return null;
	}
	public static String map2URLParams(Map<String,String> map){
		StringBuffer r=new StringBuffer();
		Iterator keys=map.keySet().iterator();
		
		while(keys.hasNext()){
			String key=(String)keys.next();
			String value=map.get(key);
			if(r.length()>0){
				r.append('&');
			}
			else {
				r.append('?');
			}
			r.append(key).append("=").append(value);
		}
		return r.toString();
	}
	public static void main(String[] args){
		System.out.println(getWeiboCode("http://dev.19lou.cn/code=agbdadfefwqef"));
	}
}

